<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-row type="flex" justify="space-between" :gutter="30">
        <el-col :span="12">
          <div class="left-box">左盒子</div>
        </el-col>
        <el-col :span="12">
          <div class="rigth-box">右盒子</div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import * as echarts from 'echarts'
import { getTotalOrder, getTotalMoney } from '@/api/index'
export default {
  name: 'Dashboard',
  data() {
    return {
      orderMonth: [],
      orderNum: [],
      orderMonthMoney: [],
      orderMoney: []
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  created() {
  },
  async mounted() {
    await this.getOrder()
    this.setLeftEcharts()
    this.setRigthEcharts()
  },
  methods: {
    async getOrder() {
      const res1 = await getTotalOrder()
      const res2 = await getTotalMoney()
      this.orderMonth = res1.data.data.map(v => v.yearAndmonth)
      this.orderNum = res1.data.data.map(v => v.orderNumber)
      this.orderMonthMoney = res2.data.data.map(v => v.yearAndmonth)
      this.orderMoney = res2.data.data.map(v => v.orderMoney)
      console.log('res2====', res2)
    },
    // 左边
    setLeftEcharts() {
      const myChart = echarts.init(document.querySelector('.left-box'))
      const option = {
        title: {
          text: '每月总订单'
        },
        xAxis: {
          type: 'category',
          data: this.orderMonth
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: this.orderNum,
            type: 'line'
          }
        ]
      }
      option && myChart.setOption(option)
    },
    // 右边
    setRigthEcharts() {
      const myChart = echarts.init(document.querySelector('.rigth-box'))
      const option = {
        title: {
          text: '每月总金额'
        },
        xAxis: {
          type: 'category',
          data: this.orderMonthMoney
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: this.orderMoney,
            type: 'bar'
          }
        ]
      }
      option && myChart.setOption(option)
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
.left-box,
  .rigth-box{
    height: 600px;
    border: 1px solid #000;
  }
</style>
